package com.dao.green.cn.databinding01.uis.activities;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.util.Log;
import android.view.View;

import com.dao.green.cn.databinding01.R;
import com.dao.green.cn.databinding01.beans.UserBean;
import com.dao.green.cn.databinding01.databinding.ActivityMainBinding;
import com.dao.green.cn.databinding01.uis.base.BaseActivity;

public class MainActivity extends BaseActivity {

    private ActivityMainBinding binding;
    private UserBean user;
    private NotificationManager notificationManager;

    @Override
    public void binding() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {
        binding.setPresenter(new Presenter());
    }

    public void setUser() {
        user = new UserBean();
        user.setName("katy");
        user.setAddress("my address");
        user.setPassword("my password");
        user.setId(123123112L);
        binding.setUser(user);
    }

    @Override
    public void initListener() {

    }


    public class Presenter implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.ac_main_obt01:
                    Log.i("TAG", "onClicked");
                    setUser();
                    break;
                case R.id.ac_main_obt02:
                    //Toast.makeText(MainActivity.this,user.getName(),Toast.LENGTH_SHORT).show();
                    break;
            }
        }

        private void showNotification() {
            PendingIntent intent = PendingIntent.getActivity(MainActivity.this, 0, new Intent(MainActivity.this, Demo01.class), 0);
            Notification notification = new Notification.Builder(MainActivity.this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentText("contentText")
                    .setContentTitle("title")
                    .setContentIntent(intent)
                    .setNumber(2)
                    .getNotification();
            notificationManager.notify(12, notification);
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            Log.e(TAG, "string=" + s.toString());
        }
    }
}
